package routes

import (
	"etcd/e"
	"etcd/utile"
	"github.com/gin-gonic/gin"
	"net/http"
)

var r *gin.Engine


func LoadRoutes(router *gin.Engine) {
	r = router
	r.Static("/static", "./static")
	r.Static("/js", "./static/layuimini/js")
	r.Static("/lib", "./static/layuimini/lib")
	r.Static("/page", "./static/layuimini/page")
	r.Static("/api", "./static/layuimini/api")
	r.Static("/css", "./static/layuimini/css")
	r.Static("/images", "./static/layuimini/images")
	r.StaticFile("/", "./static/layuimini/index.html")
	r.StaticFile("/login", "./static/layuimini/page/login.html")
	r.LoadHTMLGlob("templates/**/*")
	r.GET("/captcha", func(c *gin.Context) {
		//c.String(200,"haha")
		id, b64s, err := utile.CreatCaptcha("math")
		code := e.SUCCESS
		var data interface{}
		if err != nil {
			code = e.ERROR_CREATE_CAPTCHA
			data = ""
		} else {
			data = map[string]string{"id": id, "value": b64s}
		}
		c.JSON(http.StatusOK, utile.ReturnData(code, e.GetMsg(code), data))
	})
	loadAdminRoute()
	loadHomeRoute()
}
